//
//  FCCConversation.swift
//  chatUIDemo
//
//  Created by admin on 2025/7/10.
//

import UIKit
import Foundation

// MARK: - Conversation Model
class FCCConversation {
    var qfcId: String
    var qfcUserId: String
    var qfcUserName: String
    var qfcUserAvatarUrl: String
    var qfcLastMessage: FCCMessage?
    var qfcUnreadCount: Int
    var qfcTimestamp: Date
    var qfcIsSystemMessage: Bool
    var qfcIsInteractiveMessage: Bool
    
    init(qfcId: String = UUID().uuidString,
         qfcUserId: String,
         qfcUserName: String,
         qfcUserAvatarUrl: String,
         qfcLastMessage: FCCMessage? = nil,
         qfcUnreadCount: Int = 0,
         qfcTimestamp: Date = Date(),
         qfcIsSystemMessage: Bool = false,
         qfcIsInteractiveMessage: Bool = false) {
        self.qfcId = qfcId
        self.qfcUserId = qfcUserId
        self.qfcUserName = qfcUserName
        self.qfcUserAvatarUrl = qfcUserAvatarUrl
        self.qfcLastMessage = qfcLastMessage
        self.qfcUnreadCount = qfcUnreadCount
        self.qfcTimestamp = qfcTimestamp
        self.qfcIsSystemMessage = qfcIsSystemMessage
        self.qfcIsInteractiveMessage = qfcIsInteractiveMessage
    }
    
    // Get display text for the last message
    func qfcGetLastMessageText() -> String {
        guard let qfcLastMessage = qfcLastMessage else {
            return ""
        }
        
        switch qfcLastMessage.qfcType {
        case .qfcText:
            if let textMessage = qfcLastMessage as? FCCTextMessage {
                return textMessage.qfcContent
            }
        case .qfcImage:
            return "[Image]"
        case .qfcAudio:
            if let audioMessage = qfcLastMessage as? FCCAudioMessage {
                return "[Voice \(audioMessage.qfcDuration)s]"
            }
        }
        
        return ""
    }
}